import hashlib
import time


def generatemd5(content):
    md5 = hashlib.md5()
    md5.update(content)
    md5 = md5.hexdigest()
    print(md5)


while True:
    try:
        num = int(input("请输入序号（文件生成请输入1，字符生成请输入2，时间戳请输入3）：\n"))
    except Exception as e:
        print(f"{e}:请按照规定输入纯数字！")
        continue
    else:
        if num == 1:
            while True:
                path = str(input("请复制要生成MD5文件的全路径及名称："))  # D:\test\C06A\com.chaomeng.c06a-v3.4.0-release-2020032312.apk
                try:
                    f = open(rf'{path}', 'rb')
                except Exception as e:
                    print(f"{e}:请重新输入路径且和确保路径和文件名是否正确！")
                    continue
                else:
                    generatemd5(f.read())
                    f.close()
                    time.sleep(30)
                    break
            break
        elif num == 2:
            contents = str(input(f"{num}.请输入或复制要进行MD5加密的字符：\n")).encode('utf-8')
            generatemd5(contents)
            time.sleep(30)
            break
        elif num == 3:
            timestamp = str(time.time()).encode('utf-8')
            generatemd5(timestamp)
            time.sleep(30)
            break
        else:
            print("输入错误，请重新输入！")
            continue
